// author: Laura Montenovo
// this do file, performs the following actions for each year of data:
// 1. merges taxsim OUTPUT data to taxsim INPUT data based on family_ID 
// (there are variables from the PSID in the taxsim input data that are erased by taxsim - in taxsim output - so we keep them in through taxsim input)
// we generate a variable for the gender of the spouse of the HH head based on the marital status of the head and the sex of the head
// we merge the taxsim input+output data with the IUPUI data for that year, on family ID. The IUPUI data contains the volunteering variables we need
// we keep the same list of variables for all the years
// we save the dataset as year_IUPUI_taxsim_PSID.dta

////////////////////////////////////////////////////////////////////////////////


global root "/Volumes/Workgroup/Lab/Lab-heimb/Montenovo/Volunteering Paper/Data"
global taxsim "$root/04_TAXSIM_output"
global merge "$root/05_merged_taxsim_IUPUI_PSID" 
global IUPUI "/Volumes/Workgroup/Lab/Lab-heimb/Montenovo/Volunteering Paper/IUPUI Volunteer Data"
global dictionaries "$root/Dictionaries"

cd "$dictionaries"
capture log close
log using append_IUPUI_PSID, replace

cd "$taxsim/2001"

use taxsim27_2001_otheritem.dta, clear //11,270
cd "$taxsim/2001/plus100"

merge 1:1 individual_id using taxsim27_2001_otheritem_plus100.dta
drop _merge //11,270

cd "$root/03_ready_for_TAXSIM/taxsim_input/2001"

merge 1:1 individual_id using taxsim_input_otheritem.dta
drop if _merge!=3
drop _merge //11,270


//gen sex_spouse=.
//replace sex_spouse=1 if marital_status_head==1 & sex_head==2
//replace sex_spouse=2 if marital_status_head==1 & sex_head==1

cd "$IUPUI"

merge m:1 family_id using IUPUI_2001.dta
// 11,270

keep unique_id_crossys frate srate frate_otheritem_plus100 srate_otheritem_plus100 sequence_num year state federalTax stateTax federalTax_otheritem_plus100 stateTax_otheritem_plus100 interview_number_1986 family_id marital_status_head white_w black_w white_h black_h page sage release_number person_number state_residence sex_head children property_tax_annual mortgage1_principle_remaining mortgage1_interest_rate_wholenum mortgage1_interest_rate_fraction rent_amount rent_amount_unit childcare_expense food_stamps food_stamps_unit food_homestamps food_homestamps_unit food_deliveredstamps food_deliveredstamps_unit food_awaystamps food_awaystamps_unit food_home food_home_unit food_delivered food_delivered_unit food_away food_away_unit rent_inc_head rent_inc_head_unit dividend_inc_head dividend_inc_head_unit interest_inc_head interest_inc_head_unit tanf_inc_head tanf_inc_head_unit ssi_inc_head ssi_inc_head_unit vapension_inc_head vapension_inc_head_unit nonva_retire_inc_head nonva_retire_inc_head_unit unemployment_inc_head unemployment_inc_head_unit workerscomp_inc_head workerscomp_inc_head_unit childsupport_inc_head childsupport_inc_head_unit alimony_inc_head alimony_inc_head_unit unemployment_inc_wife unemployment_inc_wife_unit workerscomp_inc_wife workerscomp_inc_wife_unit dividend_inc_wife dividend_inc_wife_unit interest_inc_wife interest_inc_wife_unit ssi_inc_wife ssi_inc_wife_unit tanf_inc_wife tanf_inc_wife_unit childsupport_inc_wife childsupport_inc_wife_unit otherwelfare_inc_wife otherwelfare_inc_wife_unit retire_annuities_inc_wife retire_annuities_inc_wife_unit whether_itemized itemized_charitable itemized_medical alimony_given unincorp_assetpt_inc_head_gen gardening_inc_head_gen labor_inc_head_gen unincorp_assetpt_inc_wife_gen swages socsec_inc_fu taxable_inc_hh_gen native_amer_w asian_w other_w any_race_w native_amer_h asian_h other_h any_race_h taxsimid mstat depx dep13 dep17 dep18 dividend_inc_head_gen dividend_inc_wife_gen dividends rent_inc_head_gen rent_inc_wife_gen alimony_inc_head_gen asset_income head_labor_income head_labor_income2 pwages interest_inc_head_gen interest_inc_wife_gen  intrec stcg ltcg nonprop otherprop nonva_retire_inc_head_gen retire_annuities_inc_wife_gen pensions gssi unemployment_inc_head_gen unemployment_inc_wife_gen ui ssi_inc_head_gen ssi_inc_wife_gen vapension_inc_head_gen workerscomp_inc_head_gen workerscomp_inc_wife_gen tanf_inc_head_gen tanf_inc_wife_gen otherwelfare_inc_head_gen childsupport_inc_head_gen childsupport_inc_wife_gen transfers rentpaid proptax item_char item_med otheritem childcare mortgage_principle mortgage_rate_whole mortgage_rate_frac mortgage_rate mortgage Hyear Wyear hoursWLB total_giving hispanic_head hispanic_wife education_head education_wife _merge Hyear Wyear hoursHLB hoursWLB deductions_allowed hr_wage_hd hr_wage_spouse tot_wage_hd tot_wage_spouse tot_hs_worked_head tot_hs_worked_spouse religion_spouse religion_hd rural whether_unemployed_head whether_unemployed_spouse

cd "$merge"

save 2001_IUPUI_taxsim_PSID.dta, replace //11,270

////////////////////////////////////////////////////////////////////////////////

cd "$taxsim/2003"

use taxsim27_2003_otheritem.dta, clear //11,766
cd "$taxsim/2003/plus100"
merge 1:1 individual_id using taxsim27_2003_otheritem_plus100.dta
drop _merge

cd "$root/03_ready_for_TAXSIM/taxsim_input/2003"

merge 1:1 individual_id using taxsim_input_otheritem.dta
drop if _merge!=3
drop _merge

//gen sex_spouse=.
//replace sex_spouse=1 if marital_status_head==1 & sex_head==2
//replace sex_spouse=2 if marital_status_head==1 & sex_head==1

cd "$IUPUI"

merge m:1 family_id using IUPUI_2003.dta

keep unique_id_crossys frate srate frate_otheritem_plus100 srate_otheritem_plus100 sequence_num year state federalTax stateTax federalTax_otheritem_plus100 stateTax_otheritem_plus100 interview_number_1986 family_id state mstat children depx children dep13 dep17 dep18  page sage federalTax stateTax dividends pwages swages intrec stcg ltcg otherprop nonprop pensions gssi ui transfers rentpaid proptax otheritem childcare  mortgage Hyear Wyear hoursHLB hoursWLB total_giving hispanic_head hispanic_wife education_head education_wife year state frate srate  taxable_inc_hh_gen white_h black_h native_amer_h asian_h  other_h whether_itemized white_w black_w native_amer_w asian_w  other_w sex_head marital_status_head Arelig Ayouth Aenvir Acomb Aneed Ahlth Aeduc Aart Aneig Aintl Aoth Asecular10 ArelgHLB ArelgWLB AyothHLB AyothWLB AsenrHLB AsenrWLB AhlthHLB AhlthWLB AneedHLB AneedWLB AsoclHLB AsoclWLB AothrHLB AothrWLB AsecularHLB AsecularWLB whether_donation_religious amount_donation_religious whether_donation_combo amount_donation_combo whether_donation_needy amount_donation_needy whether_donation_health amount_donation_health whether_donation_education amount_donation_education whether_donation_youth amount_donation_youth whether_donation_culture amount_donation_culture whether_donation_community amount_donation_community whether_donation_environment amount_donation_environment whether_donation_peace amount_donation_peace whether_donation_other amount_donation_other donation_type_other_org calcul_yr_hs_reli_hd calcul_yr_hs_reli_wf calcul_yr_hs_reli_right_hd calcul_yr_hs_reli_right_wf your_estim_yr_hs_reli_hd your_estim_yr_hs_reli_wf estim_yr_hs_reli_extra_hd estim_yr_hs_reli_extra_wf calcul_yr_hs_reli_hd calcul_yr_hs_reli_wf calcul_yr_hs_youth_right_hd calcul_yr_hs_youth_right_wf your_estim_yr_hs_youth_hd your_estim_yr_hs_youth_wf estim_yr_hs_youth_extra_hd  calcul_yr_hs_youth_hd calcul_yr_hs_youth_wf estim_yr_hs_youth_extra_wf calcul_yr_hs_senior_hd calcul_yr_hs_senior_wf calcul_yr_hs_senior_right_hd calcul_yr_hs_senior_right_wf your_estim_yr_hs_senior_hd your_estim_yr_hs_senior_wf estim_yr_hs_senior_extra_hd estim_yr_hs_senior_extra_wf calcul_yr_hs_health_hd calcul_yr_hs_health_wf calcul_yr_hs_health_right_hd calcul_yr_hs_health_right_wf your_estim_yr_hs_health_hd your_estim_yr_hs_health_wf estim_yr_hs_health_extra_hd estim_yr_hs_health_extra_wf calcul_yr_hs_needy_hd calcul_yr_hs_needy_wf calcul_yr_hs_needy_right_hd calcul_yr_hs_needy_right_wf your_estim_yr_hs_needy_hd your_estim_yr_hs_needy_wf estim_yr_hs_needy_extra_hd estim_yr_hs_needy_extra_wf calcul_yr_hs_change_hd calcul_yr_hs_change_wf calcul_yr_hs_change_right_hd calcul_yr_hs_change_right_wf your_estim_yr_hs_change_hd your_estim_yr_hs_change_wf estim_yr_hs_change_extra_hd estim_yr_hs_change_extra_wf calcul_yr_hs_other_hd calcul_yr_hs_other_wf calcul_yr_hs_other_right_hd calcul_yr_hs_other_right_wf your_estim_yr_hs_change_hd your_estim_yr_hs_change_wf estim_yr_hs_other_extra_hd estim_yr_hs_other_extra_wf hs_other_religious hs_other_youth hs_other_senior hs_other_health hs_other_needy hs_other_socialchange volunteer_type_other_oth hs_type_other deductions_allowed hr_wage_hd hr_wage_spouse tot_wage_hd tot_wage_spouse tot_hs_worked_head tot_hs_worked_spouse religion_spouse religion_hd rural whether_unemployed_head whether_unemployed_spouse

cd "$merge"

save 2003_IUPUI_taxsim_PSID.dta, replace //11,766

*fsum, lab

////////////////////////////////////////////////////////////////////////////////

cd "$taxsim/2005"

use taxsim27_2005_otheritem.dta, clear
cd "$taxsim/2005/plus100"

merge 1:1 individual_id using taxsim27_2005_otheritem_plus100.dta
drop _merge

cd "$root/03_ready_for_TAXSIM/taxsim_input/2005"

merge 1:1 individual_id using taxsim_input_otheritem.dta
drop if _merge!=3
drop _merge

//gen sex_spouse=.
//replace sex_spouse=1 if marital_status_head==1 & sex_head==2
//replace sex_spouse=2 if marital_status_head==1 & sex_head==1

cd "$IUPUI"

merge m:1 family_id using IUPUI_2005.dta

keep unique_id_crossys frate srate frate_otheritem_plus100 srate_otheritem_plus100 sequence_num year state federalTax stateTax federalTax_otheritem_plus100 stateTax_otheritem_plus100 interview_number_1986 family_id state mstat children depx children dep13 dep17 dep18  page sage federalTax stateTax  dividends pwages swages intrec stcg ltcg otherprop nonprop pensions gssi ui transfers rentpaid proptax otheritem childcare  mortgage Hyear Wyear hoursHLB hoursWLB total_giving hispanic_head hispanic_wife education_head education_wife year state taxable_inc_hh_gen white_h black_h native_amer_h asian_h  other_h whether_itemized white_w black_w native_amer_w asian_w  other_w sex_head marital_status_head Arelig Ayouth Aenvir Acomb Aneed Ahlth Aeduc Aart Aneig Aintl Aoth Asecular10 ArelgHLB ArelgWLB AyothHLB AyothWLB AsenrHLB AsenrWLB AhlthHLB AhlthWLB AneedHLB AneedWLB AsoclHLB AsoclWLB AothrHLB AothrWLB AsecularHLB AsecularWLB whether_donation_religious amount_donation_religious whether_donation_combo amount_donation_combo whether_donation_needy amount_donation_needy whether_donation_health amount_donation_health whether_donation_education amount_donation_education whether_donation_youth amount_donation_youth whether_donation_culture amount_donation_culture whether_donation_community amount_donation_community whether_donation_environment amount_donation_environment whether_donation_peace amount_donation_peace whether_donation_other amount_donation_other donation_type_other_org calcul_yr_hs_reli_hd calcul_yr_hs_reli_wf calcul_yr_hs_reli_right_hd calcul_yr_hs_reli_right_wf your_estim_yr_hs_reli_hd your_estim_yr_hs_reli_wf estim_yr_hs_reli_extra_hd estim_yr_hs_reli_extra_wf calcul_yr_hs_reli_hd calcul_yr_hs_reli_wf calcul_yr_hs_youth_right_hd calcul_yr_hs_youth_right_wf your_estim_yr_hs_youth_hd your_estim_yr_hs_youth_wf estim_yr_hs_youth_extra_hd  calcul_yr_hs_youth_hd calcul_yr_hs_youth_wf estim_yr_hs_youth_extra_wf calcul_yr_hs_senior_hd calcul_yr_hs_senior_wf calcul_yr_hs_senior_right_hd calcul_yr_hs_senior_right_wf your_estim_yr_hs_senior_hd your_estim_yr_hs_senior_wf estim_yr_hs_senior_extra_hd estim_yr_hs_senior_extra_wf calcul_yr_hs_health_hd calcul_yr_hs_health_wf calcul_yr_hs_health_right_hd calcul_yr_hs_health_right_wf your_estim_yr_hs_health_hd your_estim_yr_hs_health_wf estim_yr_hs_health_extra_hd estim_yr_hs_health_extra_wf calcul_yr_hs_needy_hd calcul_yr_hs_needy_wf calcul_yr_hs_needy_right_hd calcul_yr_hs_needy_right_wf your_estim_yr_hs_needy_hd your_estim_yr_hs_needy_wf estim_yr_hs_needy_extra_hd estim_yr_hs_needy_extra_wf calcul_yr_hs_change_hd calcul_yr_hs_change_wf calcul_yr_hs_change_right_hd calcul_yr_hs_change_right_wf your_estim_yr_hs_change_hd your_estim_yr_hs_change_wf estim_yr_hs_change_extra_hd estim_yr_hs_change_extra_wf calcul_yr_hs_other_hd calcul_yr_hs_other_wf calcul_yr_hs_other_right_hd calcul_yr_hs_other_right_wf your_estim_yr_hs_change_hd your_estim_yr_hs_change_wf estim_yr_hs_other_extra_hd estim_yr_hs_other_extra_wf hs_other_religious hs_other_youth hs_other_senior hs_other_health hs_other_needy hs_other_socialchange volunteer_type_other_oth hs_type_other deductions_allowed hr_wage_hd hr_wage_spouse tot_wage_hd tot_wage_spouse tot_hs_worked_head tot_hs_worked_spouse religion_spouse religion_hd rural whether_unemployed_head whether_unemployed_spouse


cd "$merge"

save 2005_IUPUI_taxsim_PSID.dta, replace

*fsum, lab


////////////////////////////////////////////////////////////////////////////////
/*
global root_path "D:/Brad Heim/PSID_taxsim"
cd "$root_path/fam2007er"

merge 1:1 family_id using taxsim_input.dta
drop if _merge!=3
drop _merge

cd "D:/Brad Heim/IUPUI Volunteer Data"

merge 1:1 family_id using fam-cr299_2007_EXTRACT_v004.dta

fsum, lab
*/

////////////////////////////////////////////////////////////////////////////////

cd "$taxsim/2011"

use taxsim27_2011_otheritem.dta, clear
cd "$taxsim/2011/plus100"

merge 1:1 individual_id using taxsim27_2011_otheritem_plus100.dta
drop _merge

cd "$root/03_ready_for_TAXSIM/taxsim_input/2011"

merge 1:1 individual_id using taxsim_input_otheritem.dta
drop if _merge!=3
drop _merge

//gen sex_spouse=.
//replace sex_spouse=1 if marital_status_head==1 & sex_head==2
//replace sex_spouse=2 if marital_status_head==1 & sex_head==1

cd "$IUPUI"

merge m:1 family_id using IUPUI_2011.dta

rename type_other_org donation_type_other_org

*no info on hours worked in this case
keep unique_id_crossys frate srate frate_otheritem_plus100 srate_otheritem_plus100 sequence_num year state federalTax stateTax federalTax_otheritem_plus100 stateTax_otheritem_plus100 interview_number_1986 family_id state mstat children depx children dep13 dep17 dep18  page sage federalTax stateTax dividends pwages swages intrec stcg ltcg otherprop nonprop pensions gssi ui transfers rentpaid proptax otheritem childcare  mortgage  Hyear Wyear total_giving hispanic_head hispanic_wife education_head education_wife year state taxable_inc_hh_gen white_h black_h native_amer_h asian_h  other_h whether_itemized white_w black_w native_amer_w asian_w  other_w sex_head marital_status_head VltrH_relig VltrW_relig VltrH_youth VltrH_senior VltrH_health VltrH_poverty VltrH_change VltrH_other VltrW_youth VltrW_senior VltrW_health VltrW_poverty VltrW_change VltrW_other Arelig Ayouth Aenvir Acomb Aneed Ahlth Aeduc Aart Aneig Aintl Aoth Asecular10 whether_donation_religious amount_donation_religious whether_donation_combo amount_donation_combo whether_donation_needy amount_donation_needy whether_donation_health amount_donation_health whether_donation_education amount_donation_education whether_donation_youth amount_donation_youth whether_donation_culture amount_donation_culture whether_donation_community amount_donation_community whether_donation_environment amount_donation_environment whether_donation_peace amount_donation_peace whether_donation_other amount_donation_other donation_type_other_org whether_volunteer_religious_hd whether_volunteer_youth_hd whether_volunteer_senior_hd whether_volunteer_health_hd whether_volunteer_needy_hd whether_volunteer_socchange_hd whether_volunteer_other_hd whether_volunteer_religious_wf whether_volunteer_youth_wf whether_volunteer_senior_wf whether_volunteer_health_wf whether_volunteer_needy_wf whether_volunteer_socchange_wf whether_volunteer_other_wf type_volunteer_hd type_volunteer_wf deductions_allowed hr_wage_hd hr_wage_spouse tot_wage_hd tot_wage_spouse tot_hs_worked_head tot_hs_worked_spouse religion_spouse religion_hd rural whether_unemployed_head whether_unemployed_spouse

cd "$merge"

save 2011_IUPUI_taxsim_PSID.dta, replace //12,004
*fsum, lab


////////////////////////////////////////////////////////////////////////////////

cd "$taxsim/2017"

use taxsim27_2017_otheritem.dta, clear
cd "$taxsim/2017/plus100"

merge 1:1 individual_id using taxsim27_2017_otheritem_plus100.dta
drop _merge

cd "$root/03_ready_for_TAXSIM/taxsim_input/2017"

merge 1:1 individual_id using taxsim_input_otheritem.dta
drop if _merge!=3
drop _merge


//gen sex_spouse=.
//replace sex_spouse=1 if marital_status_head==1 & sex_head==2
//replace sex_spouse=2 if marital_status_head==1 & sex_head==1

cd "$IUPUI"

merge m:1 family_id using IUPUI_2017.dta

keep unique_id_crossys frate srate frate_otheritem_plus100 srate_otheritem_plus100 sequence_num year state federalTax stateTax federalTax_otheritem_plus100 stateTax_otheritem_plus100 interview_number_1986 family_id state mstat children depx children dep13 dep17 dep18  page sage federalTax stateTax dividends pwages swages intrec stcg ltcg otherprop nonprop pensions gssi ui transfers rentpaid proptax otheritem childcare  mortgage family_id Hyear Wyear hoursHLB hoursWLB total_giving hispanic_head hispanic_wife education_head education_wife year state taxable_inc_hh_gen white_h black_h native_amer_h asian_h  other_h whether_itemized white_w black_w native_amer_w asian_w  other_w sex_head marital_status_head deductions_allowed hr_wage_hd hr_wage_spouse tot_wage_hd tot_wage_spouse tot_hs_worked_head tot_hs_worked_spouse religion_spouse religion_hd rural whether_unemployed_head whether_unemployed_spouse

cd "$merge"

save 2017_IUPUI_taxsim_PSID.dta, replace

////////////////////////////////////////////////////////////////////////////////

cd "$taxsim/2019"

use taxsim27_2019_otheritem.dta, clear

cd "$taxsim/2019/plus100"

merge 1:1 individual_id using taxsim27_2019_otheritem_plus100.dta
drop _merge

cd "$root/03_ready_for_TAXSIM/taxsim_input/2019"

merge 1:1 individual_id using taxsim_input_otheritem.dta
drop if _merge!=3
drop _merge

//gen sex_spouse=.
//replace sex_spouse=1 if marital_status_head==1 & sex_head==2
//replace sex_spouse=2 if marital_status_head==1 & sex_head==1

cd "$IUPUI"

merge m:1 family_id using IUPUI_2019.dta

keep unique_id_crossys frate srate frate_otheritem_plus100 srate_otheritem_plus100 sequence_num year state federalTax stateTax federalTax_otheritem_plus100 stateTax_otheritem_plus100 interview_number_1986 family_id state mstat children depx children dep13 dep17 dep18  page sage federalTax stateTax  dividends pwages swages intrec stcg ltcg otherprop nonprop pensions gssi ui transfers rentpaid proptax otheritem childcare  mortgage Hyear Wyear hoursHLB hoursWLB total_giving hispanic_head hispanic_wife education_head education_wife year state taxable_inc_hh_gen white_h black_h native_amer_h asian_h  other_h whether_itemized white_w black_w native_amer_w asian_w  other_w sex_head marital_status_head deductions_allowed hr_wage_hd hr_wage_spouse tot_wage_hd tot_wage_spouse tot_hs_worked_head tot_hs_worked_spouse religion_spouse religion_hd rural whether_unemployed_head whether_unemployed_spouse

cd "$merge"

save 2019_IUPUI_taxsim_PSID.dta, replace

cd "$dictionaries"
log close
*fsum, lab

**********************************************************************

